package com.z996.activity7x.ServcieApi.TaskService;

import org.activiti.engine.*;
import org.activiti.engine.task.Task;
import org.junit.Test;

import java.util.List;


public class TestDemo {


    /**
     * 任务查询
     */
    @Test
    public void test1() {

        //先构建ProcessEngineConfiguration
        ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
        //通过ProcessEngineConfiguration创建ProcessEngine，此时会创建数据库
        ProcessEngine processEngine = configuration.buildProcessEngine();

        // 创建服务类
        TaskService taskService = processEngine.getTaskService();
        List<Task> list = taskService.createTaskQuery().processDefinitionKey("evection_my").taskAssignee("cqh").list();
        for (Task task : list) {

            System.out.println("流程实例id：" + task.getProcessInstanceId());
            System.out.println("任务id：" + task.getId());
            System.out.println("任务负责人：" + task.getAssignee());
            System.out.println("任务名称：" + task.getName());

        }
    }

    /**
     * 流程任务处理
     */
    @Test
    public void test2() {

        //先构建ProcessEngineConfiguration
        ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
        //通过ProcessEngineConfiguration创建ProcessEngine，此时会创建数据库
        ProcessEngine processEngine = configuration.buildProcessEngine();

        // 创建服务类
        TaskService taskService = processEngine.getTaskService();
        Task task = taskService.createTaskQuery()
                .processDefinitionKey("evection_my")
                .taskAssignee("zfh")
                .singleResult();
        taskService.complete(task.getId());


    }
}